<?php defined('SYSPATH') or die();?>

    <div class="page out" id="addUpConsumer">
        <div class="header_top">
            <a class="back-link-icon" href="javascript:;" data-rel="back"></a>
            <h1 class="page-title-bar">累计客户</h1>
        </div>
        <!-- 公用顶部 -->
        <div class="page-content" id="scrollDiv">
            <div class="tip-search-wrap">

                <form name="" id="search-form" action="javascript:;" class="fenxiao_submember_search_fm">
                    <div class="search-bar">
                        <input type="search" name="" id="submember_keyword" class="search-text" placeholder="请输入分销商名称进行搜索" />
                        <i class="search-icon"></i>
                    </div>
                 </form>
            </div>
            <div class="customer-list-container">
                <div class="fixed-data-label">总计/<span id="submember_num">0</span>个</div>
                <ul class="customer-list-wrap" id="submember_list">

                </ul>
                <div class="null-order-box hide" id="submember_list_none">
                    <div class="info">
                        <i class="icon"></i>
                        <p class="txt">您还没有客户，马上<a class="link" href="{$cmsurl}fenxiao/product">分销产品</a>获取下级</p>
                    </div>
                </div>
                <div class="no-info-bar" id="fenxiao_submember_no_more" style="display: none;">没有更多结果了！</div>
            </div>
        </div>
    </div>


    <script>
        (function()
        {
            var SITEURL = "{URL::site()}";
            var CURRENCY_SYMBOL="{Currency_Tool::symbol()}";
            var gbl_page=1;
            var gbl_is_loading=false;
            $("#scrollDiv").scroll(function () {
                if ($(this).scrollTop() > 120) {
                    $(".fixed-data-label").addClass("fixed")
                }
                else {
                    $(".fixed-data-label").removeClass("fixed")
                }


            })

            $("#scrollDiv .customer-list-container").scroll(function(){
                var scroll_top=$('#scrollDiv .customer-list-container').scrollTop();
                if(scroll_top+3>=($("#scrollDiv .customer-list-container")[0].scrollHeight - $('#scrollDiv .customer-list-container').height()))
                {

                    get_submember(gbl_page+1);

                }
            });

            //搜索按钮
            $("#scrollDiv .search-icon").click(function(){
                gbl_page=1;
                get_submember(1);
            })

            $(".fenxiao_submember_search_fm").submit(function(){
                get_submember(1);
            });

            get_submember(1);
            //获取会员列表
            function get_submember(page)
            {
                if(gbl_is_loading==false)
                {
                    gbl_is_loading=true;

                }
                else
                {
                    return;
                }

                var keyword=$("#submember_keyword").val();
                var params={
                    keyword:keyword,
                    page:page
                }
                $.ajax({
                    url:SITEURL+'fenxiao/ajax_get_submembers',
                    type:'POST', //GET
                    data:params,
                    dataType:'json',
                    success:function(data,textStatus,jqXHR){
                        gbl_is_loading=false;
                        if(data.status)
                        {
                            $("#submember_num").text(data.total);
                            var html='';
                            for(var i in data.list)
                            {
                                var row=data.list[i];
                                html+='<li><div class="hd"> <dl class="data clearfix"> <dt>'+
                            '<img src="'+row['litpic']+'" />'+
                            '</dt><dd>'+
                            '<p class="name">'+row['nickname']+'</p>'+
                            '<p class="num">'+row['account']+'</p>'+
                            '<p class="label">我的好友</p>'+
                            '</dd></dl></div><div class="bd">'+
                            '<div class="sy">我的收益<em class="num">'+CURRENCY_SYMBOL+row['total']+'</em></div>'+
                            '<dl class="data clearfix"> <dt></dt><dd>'+
                            '<p class="txt">最近一笔推广订单</p>'+
                            '<p class="date">'+row['last_order_time']+'</p>'+
                            '</dd></dl></div></li>';

                            }
                            if(page==1)
                            {
                                $("#submember_list").children().remove();
                            }
                            $("#submember_list").append(html);

                            if(data.list.length<10)
                            {
                                $("#fenxiao_submember_no_more").show();
                            }

                            if($("#submember_list li").length==0)
                            {
                                $("#submember_list_none").show();
                                $("#fenxiao_submember_no_more").hide();
                            }
                            else
                            {
                                $("#submember_list_none").hide();
                            }

                            if(html!='')
                            {
                                gbl_page = page;
                            }
                        }

                    }
                })


            }

        })();
    </script>
